package com.waigoulin.domain.order.model.aggregate;

import com.waigoulin.domain.order.model.entity.OrderEntity;
import com.waigoulin.domain.order.model.entity.ProductEntity;
import com.waigoulin.domain.order.model.valobj.OrderStatusVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDateTime;

/**
 * @FileName CreateOrderAggregate
 * @Description 创建订单的领域层聚合对象 ———— 聚合订单领域层实体对象和商品领域层实体对象
 * @Author waigoulin
 * @date 2025-07-31
 **/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CreateOrderAggregate {

    // 用户id
    private String userId;

    // 订单领域层实体对象
    private OrderEntity orderEntity;

    // 商品领域层实体对象
    private ProductEntity productEntity;

    public static OrderEntity buildOrderEntity(String productId, String productName) {
        // mvc 创建流水单
//        String orderId = RandomStringUtils.randomNumeric(16);
//        orderDao.insert(PayOrder.builder()
//                .userId(shopCartReq.getUserId())
//                .orderId(orderId)
//                .productId(shopCartReq.getProductId())
//                .productName(productVO.getProductName())
//                .orderTime(LocalDateTime.now())
//                .totalAmount(productVO.getPrice())
//                .status(Constants.OrderStatusEnum.CREATE.getCode()) // 创建的流水单默认是CREATE状态，成功创建支付单后才会调用方法修改为PAY_WAIT状态
//                .build());
        return OrderEntity.builder()
                .orderId(RandomStringUtils.randomNumeric(16))
                .productId(productId)
                .productName(productName)
                .orderTime(LocalDateTime.now())
                .orderStatusVO(OrderStatusVO.CREATE)
                .build();
    }
}


